package com.codedancer.campus.manager.api.feedbackRecordType;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.codedancer.campus.common.anno.InterfacePermission;
import com.codedancer.campus.common.core.BaseApi;
import com.codedancer.campus.common.response.ApiResponse;
import com.codedancer.campus.manager.api.feedbackRecordType.ro.FeedbackRecordTypeAddOrUpdateRo;
import com.codedancer.campus.manager.api.feedbackRecordType.ro.FeedbackRecordTypePageSearchRo;
import com.codedancer.campus.manager.service.IFeedbackRecordTypeService;
import com.codedancer.campus.manager.service.bo.feedbackRecordType.FeedbackRecordTypeAddOrUpdateBo;
import com.codedancer.campus.manager.service.bo.feedbackRecordType.FeedbackRecordTypePageSearchBo;
import com.codedancer.campus.manager.service.vo.feedbackRecordType.FeedbackRecordTypePageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/feedback-record-type")
@CrossOrigin(methods = {RequestMethod.GET, RequestMethod.POST, RequestMethod.DELETE,
    RequestMethod.PUT}, maxAge = 3600)
@Api(value = "反馈记录类型Api", description = "反馈记录类型Api", tags = "反馈记录类型Api")
public class FeedbackRecordTypeApi extends BaseApi {

    @Autowired
    private IFeedbackRecordTypeService feedbackRecordTypeService;

    @PostMapping("/add")
    @ApiOperation("添加反馈记录类型")
    @InterfacePermission(encodes = {"superAdmin","customerAdmin"})
    public ApiResponse<Void> add(
        @RequestBody @Valid @ApiParam(value = "添加反馈记录类型Ro", required = true)
            FeedbackRecordTypeAddOrUpdateRo feedbackRecordTypeAddOrUpdateRo) {
        FeedbackRecordTypeAddOrUpdateBo feedbackRecordTypeAddOrUpdateBo = BeanUtil.copyProperties(
            feedbackRecordTypeAddOrUpdateRo, FeedbackRecordTypeAddOrUpdateBo.class);
        feedbackRecordTypeService.add(feedbackRecordTypeAddOrUpdateBo);
        return success();
    }

    @PutMapping("/update/{uuid}")
    @ApiOperation("修改反馈记录类型")
    @InterfacePermission(encodes = {"superAdmin","customerAdmin"})
    public ApiResponse<Void> add(
        @RequestBody @Valid @ApiParam(value = "修改反馈记录类型Ro", required = true)
            FeedbackRecordTypeAddOrUpdateRo feedbackRecordTypeAddOrUpdateRo,
        @PathVariable(value = "uuid", required = true) @ApiParam(value = "反馈记录类型uuid", required = true) String uuid) {
        FeedbackRecordTypeAddOrUpdateBo feedbackRecordTypeAddOrUpdateBo = BeanUtil.copyProperties(
            feedbackRecordTypeAddOrUpdateRo, FeedbackRecordTypeAddOrUpdateBo.class);
        feedbackRecordTypeAddOrUpdateBo.setUuid(uuid);
        feedbackRecordTypeService.update(feedbackRecordTypeAddOrUpdateBo);
        return success();
    }

    @DeleteMapping("/delete/{uuid}")
    @ApiOperation("删除反馈记录类型")
    @InterfacePermission(encodes = {"superAdmin","customerAdmin"})
    public ApiResponse<Void> delete(
        @PathVariable(value = "uuid", required = true) @ApiParam(value = "反馈记录类型uuid", required = true) String uuid) {
        feedbackRecordTypeService.delete(uuid);
        return success();
    }

    @GetMapping("/page")
    @ApiOperation("分页查询反馈记录类型")
    @InterfacePermission(encodes = {"superAdmin","customerAdmin"})
    public ApiResponse<IPage<FeedbackRecordTypePageVo>> page(
        @ApiParam(value = "反馈记录类型分页查询Ro", required = false)
            FeedbackRecordTypePageSearchRo feedbackRecordTypePageSearchRo) {
        FeedbackRecordTypePageSearchBo feedbackRecordTypePageSearchBo = BeanUtil.copyProperties(
            feedbackRecordTypePageSearchRo, FeedbackRecordTypePageSearchBo.class);
        return success(feedbackRecordTypeService.page(feedbackRecordTypePageSearchBo));
    }
}
